#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include "arr.h"

int* createArr(int len){
	int* p = (int*)malloc(sizeof(int)*len);
	if(p == NULL){
		printf("Failed in CreatingArr!\n");
		return NULL;
	}
	//赋随机值
	//srand((unsigned)time(NULL));
	for(int i=0;i<len;i++){
		p[i]=rand()%100;//0-99的数字
	}
	return p;
}

void freeArr(int *p){
	free(p);
}

void printArr(int *arr,int len){
	int numInLine=20;//每行打印多少个数字
	for(int i=0;i<len;i++){
		printf("%-3d", arr[i]);
		if((i+1)%numInLine == 0)
			printf("\n");
	}
	if(len%numInLine != 0)
		printf("\n");
}

int* copyArr(int *orgArr, int len){
	int *p=(int *)malloc(sizeof(int)*len);
	if(p == NULL){
		printf("数组拷贝失败\n");
		return NULL;
	}
	//for(int i=0;i<len;i++){
	//	p[i]=orgArr[i];
	//}
	memcpy(p, orgArr, sizeof(int)*len);
	return p;
}
